﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Globalization;

namespace sipfe.util
{
    public class UtilitariosUtil
    {
        private static UtilitariosUtil singleton = null;

        public static UtilitariosUtil getInstance()
        {
            if (singleton == null)
            {
                singleton = new UtilitariosUtil();
            }
            return singleton;
        }

        public string Encriptar(string str)
        {
            //1aba17f3fac4cbb0bfad3b067610101da462bbab
            
            SHA1 sha1 = SHA1Managed.Create();
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] stream = null;
            StringBuilder sb = new StringBuilder();
            stream = sha1.ComputeHash(encoding.GetBytes(str));
            for (int i = 0; i < stream.Length; i++) sb.AppendFormat("{0:x2}", stream[i]);
            return sb.ToString();
        }

        public static DateTime FechaHoyHHMMSS()
        {
            IFormatProvider provider = new CultureInfo("es-PE", true);
            String format = "dd/MM/yyyy HH:mm:ss";
            DateTime dtHoy = DateTime.Now;
            string hoyString = dtHoy.ToString("dd/MM/yyyy HH:mm:ss");           
            return DateTime.ParseExact(hoyString, format, provider);
        }
        public static DateTime FechaHoy()
        {
            IFormatProvider provider = new CultureInfo("es-PE", true);
            String format = "dd/MM/yyyy";
            DateTime dtHoy = DateTime.Now;
            string hoyString = dtHoy.ToString("dd/MM/yyyy");
            return DateTime.ParseExact(hoyString, format, provider);
        }
        public static DateTime FechaAyer()
        {
            IFormatProvider provider = new CultureInfo("es-PE", true);
            String format = "dd/MM/yyyy";
            DateTime dtAyer = DateTime.Now.AddDays(-1);
            string hoyString = dtAyer.ToString("dd/MM/yyyy");
            return DateTime.ParseExact(hoyString, format, provider);
        }




    }
}
